package cn.itcast.service.impl;

import cn.itcast.dao.AreaDao;
import cn.itcast.domain.Area;
import cn.itcast.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AreaServiceImpl implements AreaService {


    /**
     * 批量导入
     */
    @Autowired
    private AreaDao areaDao;
    @Override
    public void save(List<Area> area) {
        for (Area area1 : area) {
            areaDao.save(area1);
        }


    }

    @Override
    public Page<Area> pageQuery(int page, int rows,Area area) {
        PageRequest pageList = PageRequest.of(page-1, rows);

        ExampleMatcher matcher = ExampleMatcher.matching()
                .withMatcher("province" ,ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("city" ,ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("district" ,ExampleMatcher.GenericPropertyMatchers.contains());


        return  areaDao.findAll(Example.of(area,matcher),pageList);
    }

    /**
     * 根据id删除
     * @param ids
     */

    @Override
    public void areaDelBatch(String ids) {
        areaDao.deleteById(ids);
    }

    @Override
    public void save(Area area) {
        areaDao.save(area);
    }
}
